package edu.tcc.iot.domain;

import java.util.ArrayList;
import java.util.List;

public class Shelf {
	
	public final long id;
	private List<Product> products;

	public Shelf(long id) {
		this.id = id;
		products = new ArrayList<Product>();
	}
	
	public long getId() {
		return id;
	}
	
	public List<Product> getProducts() {
		return products;
	}

	public boolean existProduct(Product product) {
		for(Product prod : products){
			if(product.getId() == prod.getId()){
				return true;
			}
		}
		return false;
	}

	public void updateProduct(Product product) {
		for(Product prod : products){
			if(product.getId() == prod.getId()){
				product.setProductInfo(prod.getProductInfo());
			}
		}
	}

	public void addProduct(Product product) {
		products.add(product);		
	}

	public void setProductList(List<Product> products) {
		this.products = products;
		
	}

	public boolean isProductEqual(Product product) {
		boolean result = false;
		for(Product prod : products){
			if(product.equals(prod)){
				result = true;
			}
		}
		return result;
	}
	
	@Override
	public String toString() {
		return "[Shelf Id: " + id + " ]";
	}

}
